--Submitted by Devilleather
LogAlways("Loading KillStreaks");
-- function TeamInstantAction.Server:OnPlayerKilled(hit)
--    local target=hit.target;
--    target.death_time=_time;
--    target.death_pos=target:GetWorldPos(target.death_pos);
--
--    local tk = self:IsTeamKill(hit.target, hit.shooter);
--    self.game:KillPlayer(hit.targetId, not tk, true, hit.shooterId, hit.weaponId, hit.damage, hit.materialId, hit.typeId, hit.dir);
--    self:ProcessScores(hit, tk);
--    XKillStreak(hit.shooter, hit.target);
-- end
function InstantAction.Server:OnPlayerKilled(hit)
    local target=hit.target;
    target.death_time=_time;
    target.death_pos=target:GetWorldPos(target.death_pos);

    self.game:KillPlayer(hit.targetId, true, true, hit.shooterId, hit.weaponId, hit.damage, hit.materialId, hit.typeId, hit.dir);
    self:ProcessScores(hit);

    local vehicleId=target.actor:GetLinkedVehicleId();
    if (vehicleId) then
        local vehicle=System.GetEntity(vehicleId);
        if (vehicle) then
            vehicle.x_lock = nil;
        end
    end
    XKillStreak(hit.shooter, hit.target);
    XSafeCall(XLiveInfo, hit.shooter, hit.target);
    LogAlways("Player Killed - InstantAction.Server:OnPlayerKilled  <KillStreaks.lua>");
end

function XLiveInfo(shooter, target)
	local shooterKills 		= g_gameRules.game:GetSynchedEntityValue(shooter.id, g_gameRules.SCORE_KILLS_KEY)
	local shooterDeaths 	= g_gameRules.game:GetSynchedEntityValue(shooter.id, g_gameRules.SCORE_DEATHS_KEY)
	local shooterHeadys 	= g_gameRules.game:GetSynchedEntityValue(shooter.id, g_gameRules.SCORE_HEADSHOTS_KEY)
	local targetKills 		= g_gameRules.game:GetSynchedEntityValue(target.id, g_gameRules.SCORE_KILLS_KEY)
	local targetDeaths		= g_gameRules.game:GetSynchedEntityValue(target.id, g_gameRules.SCORE_DEATHS_KEY)
	local targetHeadys		= g_gameRules.game:GetSynchedEntityValue(target.id, g_gameRules.SCORE_HEADSHOTS_KEY)
	XSendBigCenterMessageToPlayer(shooter, shooterKills.." kills | "..shooterHeadys.." headshots | "..shooterDeaths.." deaths") 
    XSendBigCenterMessageToPlayer(target, targetKills.." kills | "..targetHeadys.." headshots | "..targetDeaths.." deaths")
end 

-- =============================================================================
-- Function:XKillStreak
--
-- This function is called whenever a player is killed. It increments the
-- killstreak of the shooter, and if their streak is a certain length then
-- display a message to all players.
--
-- \param[in] shooter
-- The player object of the shooter.
--
-- \param[in] target
-- The player object of the target.
--
-- =============================================================================
function XKillStreak(shooter, target)
   -- Only apply the killstreaks if enabled
   if (XCfgVar.useKillStreakFeature) then
      if (not shooter.Killstreak) then
         shooter.Killstreak = 0;
      end

      -- If the kill is a suicide, do not increment killstreak
      if (shooter==target) then
         target.Killstreak = 0;
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName()..": "..shooter.Killstreak);
         end
         return;
      end

      -- increment kill streak
      shooter.Killstreak = shooter.Killstreak + 1;

      -- Kill streak output messages
      if (shooter.Killstreak==2) then
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName().."");
         end
         g_gameRules.game:SendTextMessage(TextMessageBig, "<blink><b><i><font color=\"#FF0000\">:::</font><font color=\"#FFFFFF\"> D O U B L E  K I L L </font><font color=\"#FF0000\">:::</font></blink>", TextMessageToClient, shooter.id);
      elseif (shooter.Killstreak==3) then
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName().."");
         end
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">:::</font><font color=\"#FFFFFF\"> T R I P L E  K I L L </font><font color=\"#FF0000\">:::</font>", TextMessageToClient, shooter.id);
      elseif (shooter.Killstreak==4) then
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName().."");
         end
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">:::</font><font color=\"#FFFFFF\"> M U L T I  K I L L </font><font color=\"#FF0000\">:::</font>", TextMessageToClient, shooter.id);
      elseif (shooter.Killstreak==8) then
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName().."");
         end
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">"..shooter:GetName().."</font><font color=\"#FFFFFF\"> is </font><b><i><font color=\"#FF0000\">UNSTOPPABLE!!</font>", TextMessageToAllRemote);
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">!!</font><font color=\"#FFFFFF\"> U N S T O P P A B L E </font><font color=\"#FF0000\">!!</font>", TextMessageToClient, shooter.id);
      elseif (shooter.Killstreak==10) then
         if (XCfgVar.LogKillStreaks) then
            LogAdmins(shooter:GetName().."");
         end
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">"..shooter:GetName().."</font><font color=\"#FFFFFF\"> is </font><b><i><font color=\"#FF0000\">GODLIKE!!!</font>", TextMessageToAllRemote);
         g_gameRules.game:SendTextMessage(TextMessageBig, "<b><i><font color=\"#FF0000\">!!</font><font color=\"#FFFFFF\"> G O D L I K E </font><font color=\"#FF0000\">!!</font>", TextMessageToClient, shooter.id);
      end

      -- reset the kill streak for the dead player
      target.Killstreak = 0;

      -- log kill streaks
      if (XCfgVar.LogKillStreaks) then
         LogAdmins(shooter:GetName()..": "..shooter.Killstreak);
         LogAdmins(target:GetName()..": "..target.Killstreak);
      end
   end
end